#encoding: utf-8
require "api_helpers"

module GrapeAPI
  module V1
    class MInterFace < Grape::API
      version "v1"
      helpers GrapeAPI::APIHelpers
      resource :users

      before do
        authorize_route!
      end
      
      rescue_from CanCan::AccessDenied do |exception|
        data = {:errors => "Unable to read this article.", :strtus=>"400"}.to_json
        # raise({:errors => "Unable to read this article.", :strtus=>"400"}.to_json)
        error! 'Unauthorized', 401, 'X-Error-Detail' => 'Invalid token.'
      end
      
      
      post :test, authorize: [:read, User] do
        @user = User.find(params[:id])
        {:email => @user.email.to_s}
      end
    end
  end
end